home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / idlelib / Percolator.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2005-10-18  |  3KB  |  96 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.4)
  3.  
  4. from WidgetRedirector import WidgetRedirector
  5. from Delegator import Delegator
  6.  
  7. class Percolator:
  8.     
  9.     def __init__(self, text):
  10.         self.text = text
  11.         self.redir = WidgetRedirector(text)
  12.         self.top = self.bottom = Delegator(text)
  13.         self.bottom.insert = self.redir.register('insert', self.insert)
  14.         self.bottom.delete = self.redir.register('delete', self.delete)
  15.         self.filters = []
  16.  
  17.     
  18.     def close(self):
  19.         while self.top is not self.bottom:
  20.             self.removefilter(self.top)
  21.         self.top = None
  22.         self.bottom.setdelegate(None)
  23.         self.bottom = None
  24.         self.redir.close()
  25.         self.redir = None
  26.         self.text = None
  27.  
  28.     
  29.     def insert(self, index, chars, tags = None):
  30.         self.top.insert(index, chars, tags)
  31.  
  32.     
  33.     def delete(self, index1, index2 = None):
  34.         self.top.delete(index1, index2)
  35.  
  36.     
  37.     def insertfilter(self, filter):
  38.         filter.setdelegate(self.top)
  39.         self.top = filter
  40.  
  41.     
  42.     def removefilter(self, filter):
  43.         f = self.top
  44.         if f is filter:
  45.             self.top = filter.delegate
  46.             filter.setdelegate(None)
  47.         else:
  48.             while f.delegate is not filter:
  49.                 f.resetcache()
  50.                 f = f.delegate
  51.             f.setdelegate(filter.delegate)
  52.             filter.setdelegate(None)
  53.  
  54.  
  55.  
  56. def main():
  57.     
  58.     class Tracer(Delegator):
  59.         
  60.         def __init__(self, name):
  61.             self.name = name
  62.             Delegator.__init__(self, None)
  63.  
  64.         
  65.         def insert(self, *args):
  66.             print self.name, ': insert', args
  67.             self.delegate.insert(*args)
  68.  
  69.         
  70.         def delete(self, *args):
  71.             print self.name, ': delete', args
  72.             self.delegate.delete(*args)
  73.  
  74.  
  75.     root = Tk()
  76.     root.wm_protocol('WM_DELETE_WINDOW', root.quit)
  77.     text = Text()
  78.     text.pack()
  79.     text.focus_set()
  80.     p = Percolator(text)
  81.     t1 = Tracer('t1')
  82.     t2 = Tracer('t2')
  83.     p.insertfilter(t1)
  84.     p.insertfilter(t2)
  85.     root.mainloop()
  86.     p.removefilter(t2)
  87.     root.mainloop()
  88.     p.insertfilter(t2)
  89.     p.removefilter(t1)
  90.     root.mainloop()
  91.  
  92. if __name__ == '__main__':
  93.     from Tkinter import *
  94.     main()
  95.  
  96.